//
//  YJTelephoneKeyboardView.m
//  YJB
//
//  Created by YJB on 2017/1/23.
//  Copyright © 2017年 YJB. All rights reserved.
//

#import "YJTelephoneKeyboardView.h"

@interface YJTelephoneKeyboardView ()
@end

@implementation YJTelephoneKeyboardView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
      [self setUp];
    }
    return self;
}

-(void)awakeFromNib
{
    [super awakeFromNib];
    [self setUp];
}

- (void)setUp
{
    UIView *v = [[UIView alloc]initWithFrame:CGRectZero];
    self.telephoneInputText.inputView = v;
    self.telephoneInputText.tintColor = kUIColorFromRGB(0xff783d);
    [self.telephoneInputText becomeFirstResponder];
}

+ (YJTelephoneKeyboardView *)getTelephoneKeyboardView
{
    return [[[NSBundle mainBundle]loadNibNamed:NSStringFromClass(self) owner:nil options:nil]lastObject];
}

- (IBAction)keyBaoredBtn:(UIButton *)button
{
    NSString *num = button.currentTitle;
    [self.telephoneInputText insertText:num];
}

- (IBAction)callBtnClick:(UIButton *)button
{
    //去除首尾多余的空格
    NSString *telephone =  [self.telephoneInputText.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    if (telephone.length == 0) return;
    
    if (self.callBtnClickBlock)
        self.callBtnClickBlock(telephone);
}

- (IBAction)contactBtnClick:(UIButton *)button
{
    if (self.contactBtnClickBlock) {
        self.contactBtnClickBlock();
    }
}

- (IBAction)hiddenKeyBoardClick:(UIButton *)button
{
    
}

- (IBAction)deleteBtnClick:(UIButton *)button
{
    [self.telephoneInputText deleteBackward];
}


@end
